//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================


#include <ddk.h>
#include "dm9000.h"
#include "dm9000var.h"

//EXTERN_C void dump_buf(Byte *buf, int len, char *disc, int dump) {
//    int i;
//    Byte *data = buf;
//    if (dump) {
//        //Dprintf("+++++++++++++++++++++++++++++++++++++++++++++++\ndumpbuf: ");
//        Dprintf(L"dump buf: ");
//        if (disc != NULL)
//            Dprintf(L"%s\n", disc);
//        else
//            Dprintf(L"\n");
//        for (i = 1; i <= len; i++) {
//            Dprintf(L"%x%x ", (data[i-1] & 0xf0) >> 4, data[i-1] & 0x0f);
//            if (((i % 16) == 0))
//                Dprintf(L"\n");
//        }
//        Dprintf(L"\n");
//    }
//}



void CPLD_SetPwrIO( UInt32 pwrNum, UInt32 state )
{
    if( state )
    {
        CPLD->pwrIO |= pwrNum;
    }
    else
    {
        CPLD->pwrIO &= ~pwrNum;
    }
}

void CPLD_SetExtIO( UInt32 extNum, UInt32 state )
{
    if( state )
    {
        CPLD->extIO |= extNum;
    }
    else
    {
        CPLD->extIO &= ~extNum;
    }
}

void CPLD_SetIntMask( UInt32 intNum, UInt32 state )
{
    if( state )
    {
        CPLD->intMask |= intNum;
    }
    else
    {
        CPLD->intMask &= ~intNum;
    }
}
void Dm_Delay(UInt32 ms );
void CPLD_Init()
{
    CPLD_SetPwrIO( ETH_PWR, 1 );                            //power on
    Dm_Delay( 100 );
    CPLD_SetExtIO( ETH_RST, 1 );                            //hardware reset
    Dm_Delay( 10 );
    CPLD_SetExtIO( ETH_RST, 0 );
    Dm_Delay( 1 );
    Dm_Delay(2000);
}


void Dm_Delay( UInt32 ms )
{
    volatile UInt32 i, j;

    for( i=0; i<ms; i++ )
    {
        for( j=0; j<600; j++ );
    }
}


static ipl_t old_ipl;
void _EnableIrq()
{
    DzLowerCurrentIpl(old_ipl);
//    kprintf("open :-))\n");
}

void _DisableIrq()
{
    old_ipl = DzRaiseCurrentIpl(IPL10);
//    kprintf("close :-((\n");
}




Node::Node(unsigned long*p, int len)
{
    m_address = p;
    m_len = len;
    Initialize();
}

void Node::InsertNode(Node*p)
{
    InsertFirst(p);
}

Node* Node::GetNode()
{
    Node* pnode = (Node*)Last();
    pnode->Detach();
    return pnode;
}







